<template>
    <div class="order-list-container">
        <div class="olc-head">
            <span>订单编号：{{ ibase.number }}</span>
            <span>{{ buildStateText }}</span>
        </div>
        <div v-if="ibase.name" class="olc-shop">
            <div class="olc-shopname">
                <img src="../../../../static/images/shop.png" />
                <span>{{ ibase.name }}</span>
            </div>
            <div class="olc-time">{{ ibase.time }}</div>
        </div>
        <order-list-item :ibase="ibase" :dataset="dataset" type="salesman" />
        <div class="olc-price" :class="this.$store.state.options.user.oda.groupid==6?'paddingBottom':''">
            <p  v-if="this.$store.state.options.user.oda.groupid!=6">订单合计：<span>￥</span><span>{{ parseFloat(ibase.amount).toFixed(2) }}</span></p>
            <p v-if="ibase.protect" class="tip-footer">(价格保护已开启)</p>
        </div>
        <div :class="{'olc-footer': !stylePlan, 'olc-footer-qun': stylePlan}">
            <van-button @click="eventClickButtonOperate('adopt')" slot="button" size="small" type="primary" class="normal-diy-button" round>通过</van-button>
            <van-button @click="eventClickButtonOperate('reject')" slot="button" size="small" type="primary" class="order-assist-button" round>驳回</van-button>
        </div>
    </div>
</template>

<script>
    import { Button, Dialog } from 'vant';

    import OrderListItem from './normal-list-base.vue';

    export default {
        components: {
            [Button.name]: Button,
            OrderListItem
        },
        props: ['textType', 'ibase', 'dataset', 'mode', 'index'],
        computed: {
            buildStateText() {
                var stateText = '';
                switch(this.textType) {
                    case 'collect':
                        stateText = '待收取';
                        break;
                    case 'confirm':
                    case 'salesman-confirm':
                    case 'zhuguan-confirm':
                        stateText = '待确认';
                        break;
                    case 'complete':
                        stateText = '已完成';
                        break;
                    case 'cancel':
                        stateText = '已取消';
                        break;
                    case 'stockOut':
                        if (this.ibase.status==1){
                            stateText = '待确认';
                        } else {
                            stateText = '已出库'
                        }
                        break;
                    case 'stockEntry':
                        stateText = '待确认';
                        break;
                }

                return stateText;
            },
            stylePlan() {
                return this.ibase.style ? true : false;
            }
        },
        methods: {
            eventClickButtonOperate(mode) {
                var url = '/api/home/order/change',
                    params = {
                        type: 'shenheoutorder',
                        id: this.ibase.oda.id,
                        token: this.$store.state.options.user.token
                    };

                switch (mode) {
                    case 'adopt':
                        params.status = 2;
                        break;
                    case 'reject':
                        params.status = 4;
                        break;
                }

                this.$util.postRequestInterface(url, params, (res) => {
                    this.$emit('eventOnDeleteItem', this.index);
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
    .order-list-container {
        border-bottom: 0.4rem solid #EEEEEE;

        .olc-head {
            margin-bottom: 1rem;
            padding: 0.5rem 0rem 0.8rem;
            border-bottom: 0.1rem solid #EEEEEE;
            display: flex;
            justify-content: space-between;

            span:first-child {
                font-size: 1.3rem;
                color: #999999;
            }

            span:last-child {
                font-size: 1.3rem;
                color: #00CC00;
            }
        }
        .paddingBottom{
            padding-bottom: 1rem !important;
        }
        .olc-price {
            padding: 1rem 0rem 0rem;
            text-align: right;

            p:first-child {
                font-size: 1.4rem;
                color: #999999;

                span {
                    color: #FF0101;
                }

                span:first-child {
                    font-size: 1.4rem;
                }

                span:last-child {
                    font-size: 1.9rem;
                }
            }

            .tip-footer {
                font-size: 1.3rem;
                color: #FF9000;
            }
        }

        .olc-footer, .olc-footer-qun {
            margin-top: 1rem;
            padding: 1rem 0rem;
            border-top: 0.1rem solid #EEEEEE;
            display: flex;
            flex-direction: row-reverse;
        }

        .olc-footer-qun {
            margin: 0rem;
            padding-top: 0.5rem;
            border: none;
        }

        .olc-item {
            padding-bottom: 1rem;
            border-bottom: 0.1rem solid #EEEEEE;
        }

        .olc-shop {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 1.4rem;
            margin-bottom: 1rem;

            .olc-shopname {
                color: #666666;

                img{
                    width: 1.4rem;
                    height: 1.4rem;
                    vertical-align: bottom;
                }
            }

            .olc-time {
                color: #999999;
            }
        }
    }

    .order-assist-button {
        background-color: #ffffff;
        color: #00CC00 !important;
        padding-left: 2rem !important;
        padding-right: 2rem !important;
        font-size: 1.3rem;
        margin-right: 0.8rem;
    }
</style>
